<template>


        <a-spin :spinning="loading" tip="加载中...">
            <!--组织机构树-->
            <BasicTree v-if="!treeReloading" toolbar search showLine :checkStrictly="true" :clickRowToExpand="false"
                :treeData="treeData" :selectedKeys="selectedKeys" :expandedKeys="expandedKeys" :defaultExpandAll="true"
                :autoExpandParent="autoExpandParent" @select="onSelect" @handleSearch="handleSelect" @expand="onExpand"
                @search="onSearch" />
        </a-spin>


</template>

<script setup lang="ts">
import { inject, nextTick, ref } from 'vue';
import { BasicTree, TreeActionType } from '/@/components/Tree';
import type { TreeProps } from "ant-design-vue";
//spin是否加载
let loading = ref<boolean>(false);
// 树列表数据 - 默认数据
let   treeData: TreeProps["treeData"] = [
    {
        title: "parent 1",
        key: "0-0",
        children: [
            {
                title: "parent 1-0",
                key: "0-0-0",
                children: [
                    {
                        title: "leaf1",
                        key: "0-0-0-0",
                    },
                    {
                        title: "leaf",
                        key: "0-0-0-1",
                    },
                    {
                        title: "leaf",
                        key: "0-0-0-2",
                    },
                ],
            },
            {
                title: "parent 1-1",
                key: "0-0-1",
                children: [
                    {
                        title: "leaf",
                        key: "0-0-1-0",
                    },
                ],
            },
            {
                title: "parent 1-2",
                key: "0-0-2",
                children: [
                    {
                        title: "leaf",
                        key: "0-0-2-0",
                    },
                    {
                        title: "leaf",
                        key: "0-0-2-1",
                    },
                ],
            },
        ],
    },
];

// 当前展开的项
let expandedKeys = ref<string[]>([]);
// 当前选中的项
let selectedKeys = ref<string[]>([]);//只有multiple  才能响应数组
// 是否自动展开父级
let autoExpandParent = ref<boolean>(true);
// 树组件重新加载
let treeReloading = ref<boolean>(false);


// 加载部门信息
function loadTreeData() {
    loading.value = true;
    treeData.value = [];
    queryTreeList()
        .then((res) => {
            if (res) {
                if (Array.isArray(res)) {
                    res = [{
                        "key": "0",
                        "title": "全部",
                        "isLeaf": false,
                        "icon": null,
                        "parentId": "",
                        "value": "0",
                        "code": "",
                        "children": res,
                        "id": "0",
                        "text": "全部",
                        "leaf": false
                    }]
                    treeData.value = res;
                    autoExpandParentNode();
                }
            } else {
                createMessage.warning(res.message);
            }
        })
        .finally(() => (loading.value = false));
}

function onSelect() {
    
}
function handleSelect() {

}
function onExpand() {

}
function onSearch() {

}
</script>

<style scoped>

</style>